<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>个人打分列表</title>

		<link href="../bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="../layui/css/layui.css" media="all" />
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			
			.class_div_scorelist {
				width: 100%;
				height: 100vh;
			}
			
			.class_div_header {
				height: 15vh;
				background-image: url(../img/header.png);
				background-repeat: no-repeat;
				background-size: 100%;
			}
			
			.class_h1_header_title {
				margin: 0;
				text-align: center;
				color: #FFFFFF;
				line-height: 7vh;
			}
			
			.class_div_title {
				font-weight: bold;
				font-size: 1.3em;
			}
			
			.class_div_table {
				margin-top: 20px;
			}
			
			.td_content {
				text-align: center;
			}
			
			.tr_btngroup {
				text-align: center;
			}
			
			.tr_btngroup button {
				margin-left: 5px;
			}
			
			.class_div_btn_sub {
				float: right;
			}
			.class_div_logout{
				position: fixed;
				bottom:50px;
				right: 50px;
			}
			.class_div_logout button{
				width: 80px;
				height:40px;
			}
			#demo{
				width: 100%;
			}
		</style>
	</head>

	<body>
		<div class="class_div_scorelist">
			<div class="class_div_header">
			</div>
			<div class="row class_div_container" style="margin:0px">
				<div class="col-xs-10 col-xs-offset-1">
					<div class="class_div_table">
						<div class="container">
							<span class="class_div_title">
								个人打分列表
							</span>
							<span class="class_div_btn_sub">
								<button type="button" class="btn btn-danger" onclick="commitList()">提交打分列表</button>
							</span>
							<table id="demo" lay-filter="test"></table>
						</div>
					</div>
				</div>
			</div>
			<div class="class_div_logout">
				<a href="DaFenPage.html"><button type="button" class="btn btn-info">返回首页</button></a>
			</div>
		</div>
		<script src="../js/jquery-1.12.4/jquery.min.js"></script>
		<script src="../bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="../js/jquery-2.1.4/jquery.min.js"></script>
		<script type="text/javascript" src="../layui/layui.js"></script>
		<script type="text/javascript" src="../js/ip.js"></script>
		<script type="text/javascript">
			var currStageId;
			var currCandidateSort;
			var currId;
			var scoreInfoId = 1;
			var headerList = [ //表头
				{
					field: 'index',
					title: '序号',
					type: 'numbers',
					width: '5%',
					align: 'center',
				}, {
					field: 'candidateName',
					title: '用户名',
					align: 'center',
				}, {
					field: 'candidateSex',
					title: '性别',
					sort: true,
					align: 'center',
				}, {
					field: 'candidatePsition',
					title: '职务',
					align: 'center',
				}, {
					field: 'candidateSchool',
					title: '学校/院系',
					align: 'center',
				}, {
					field: 'candidateEducation',
					title: '学位',
					align: 'center',
				}, {
					field: 'candidateRegularPayroll',
					title: '任职经历',
					align: 'center',
				}, {
					field: 'fraction',
					title: '分数',
					sort: true,
					align: 'center',
					templet:function(d){
						if(d.fraction){
							return d.fraction
						}else{
							return '';
						}
					}
				}, {
					field: 'handel',
					title: '操作',
					toolbar: '#barDemo',
					align: 'center',
				}
			]

			$(document).ready(function() {
				getAllScoreList();
			});

			function getAllScoreList() {
				let info = new Object();
				info.stageId = 1;
				let postaddress = ip + '/grade/getall';
				$.ajax({
					//几个参数需要注意一下
					type: "POST", //方法类型
					dataType: "json", //预期服务器返回的数据类型
					contentType: "application/json;charset=utf-8",
					url: postaddress, //url
					data: JSON.stringify(info),
					success: function(result) {
						currStageId = 1;
						if(result.code == 0) {
							for(var j = 0; j<  result.data.length; j++){
								if(result.data[j].fraction === -1){
									result.data[j].fraction = "同校";
								}
							}
							layui.use('table', function() {
								var table = layui.table;
								table.render({
									elem: '#demo',
									data: result.data,
									limit:100,
									cols: [headerList],

								});
								table.on('tool()', function(obj) {
									let data = obj.data;
									const showModel = ishowModel(data.raterSchool, data.candidateSchool);
									if(obj.event === 'edit' && showModel) {
										layer.prompt({
											title: '请输入得分',
											value: data.fraction,
											formType: 0,
										}, function(value, index, elem) {
											let info = new Object();
											info.scoreInfoId = 1;
											info.stageId = 1;
											info.candidateId = data.candidateId;
											info.fraction = value;
											const postaddress = ip + '/grade/set';
											$.ajax({
												//几个参数需要注意一下
												type: "POST", //方法类型
												dataType: "json", //预期服务器返回的数据类型
												contentType: "application/json;charset=utf-8",
												url: postaddress, //url
												data: JSON.stringify(info),
												success: function(result) {
													layer.close(index);
													layer.msg('编辑成功');
													getAllScoreList();
												},
												error: function() {
													layer.msg('编辑失败');
													layer.close(index);
												}
											});

										});
									} else {
										layer.alert('同校不能进行评分！');
									}
								});

							});
						}
					},
					error: function(result) {
						alert(result.msg);
					}
				});
			}

			function ishowModel(raterSchool, candidateSchool) {
				if(raterSchool !== candidateSchool) {
					return true;
				} else {
					return false;
				}
			}

			//提交最终打分列表
			function commitList() {
				const postaddress = ip + '/grade/commit';
				let info = new Object();
				info.stageId = 1;
				$.ajax({
					//几个参数需要注意一下
					type: "POST", //方法类型
					dataType: "json", //预期服务器返回的数据类型
					contentType: "application/json;charset=utf-8",
					url: postaddress, //url
					data: JSON.stringify(info),
					success: function(result) {
						if(result.code === 0){
							window.location.href = 'DaFenPage.html';
						}
					},
					error: function() {

					}
				});
			}
		</script>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		</script>
	</body>

</html>